Skip to content

Build the kit as a PowerShell module, and test it that way - #100

Merged
HalRiveria-Bot merged 15 commits into
mainfrom
change/gallery-module
Dec 2, 2026
Merged

HalRiveria-Bot merged 15 commits into
mainfrom
change/gallery-module

Conversation

@HalRiveria-Bot

@HalRiveria-Bot HalRiveria-Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

The kit can now be built as a PowerShell module, for people who'd rather import it than dot-source a file. ParallelKit.ps1 stays the one source, dot-sources as before, and no module files are tracked.

What's new

  • Build/New-ParallelKitModule.ps1 makes ParallelKit.psm1 and its manifest. The .psm1 is the .ps1 without the wrapper that loads it as an in-memory module: nothing else changes. The manifest's version and function list come from the .ps1. It checks everything before writing anything, so a .ps1 whose loading code changed stops it with a message, and the same .ps1 always gives the same bytes, on Windows PowerShell 5.1 and PowerShell 7.
  • The harness has -AsModule, which builds the module and tests that, imported by name, instead of dot-sourcing. -Section MODULE is the 21 sections where the way it's loaded can matter. CI runs those on the module after the full run, in both jobs (about 85 s each on my machine).
  • The README has a section on the module: building and importing it, a refused import, using it from your own module, workers, and more than one copy in a session.
  • A few comments in the kit and the harness now hold for both ways of loading.

What differs from dot-sourcing (all in the README)

  • A refused import (another version's compiled types are loaded) doesn't stop the script by itself, and the copy already loaded stays.
  • Imported by another module without -Global or RequiredModules, the kit's functions aren't global, so that module's .GetNewClosure() callbacks can't call them.
  • With the module installed, a worker's call the safety check can't see can load it there.

Tests

  • New section BM: the same bytes from repeated builds and from LF or CRLF; only the wrapper gone; 18 edits of the .ps1 refused with nothing written; the manifest's version, functions and identity; eight ways of loading it, each with -File and &, with closures and a worker; and a copy with other compiled types refused while the first keeps working. Taking one check out of the generator fails it.
  • Full harness, dot-sourced: 722 passed on 5.1 and 722 passed on 7.6.2. As the module: 721 passed on 5.1 and 721 on 7.6.2 (one check is only for the dot-sourced file). No skips. Testing/readme-examples/run.ps1 passes on both.
  • PSScriptAnalyzer reports no errors on the module.
  • The first CI run timed out on 5.1: the harness gave its child processes a module analysis cache of their own, empty, so each analyzed every module on GitHub's image (several times the normal start-up, past 45 s for some). It uses the normal cache now.

🤖 Generated with Claude Code

HalRiveria and others added 15 commits December 1, 2026 16:12
Two of the batch's own closures called Complete-PkProcess and Write-PkMessage
by name. A .GetNewClosure() block only sees global functions, so a batch failed
with "'Complete-PkProcess' is not recognized" when the kit was loaded for one
module only. They're captured up front now, like the private helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A worker given the function (-SharedFunctionNames takes it) could set a handler
made in its own runspace, which the main thread then ran for every message.
Running another runspace's scriptblock can hang or crash PowerShell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It only looked for an abort after its first 200 ms wait, so a program that
finished sooner ran to the end and returned normally, and a slower one ran for
about 200 ms before it was killed. It now throws before starting the program,
unless -IgnoreAbort is given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… GetNewClosure

DelegateCast missed a scriptblock passed to .NET as ({ 1 }), { 1 }.GetNewClosure(),
[scriptblock]{ 1 } and the like, in the call or through a variable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Invoke-PkRunspaceJobs is Invoke-PkRunspaceBatch, and 13 private functions lose
their plural names. -MaxConcurrent and -AbortTimeoutSeconds are the only names
on every engine: -MaxParallel and -DrainTimeoutSeconds are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Initialize-ParallelKit loses -MaxConcurrentProcesses and ThreadPool, and the
dispatcher its -AbortPollCallback alias. Code nothing reaches goes too. The
stale-types message says "a different version". Two functions declare their
output type. The comments are shorter and checked against the code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	ParallelKit.Harness.ps1
#	ParallelKit.ps1
Build/New-ParallelKitModule.ps1 makes ParallelKit.psm1 and its manifest from
ParallelKit.ps1. The harness can run on that module (-AsModule), and CI runs the
sections where loading can matter on it. The README covers the module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit a29f02e into main Dec 2, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the change/gallery-module branch December 2, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants